package br.com.lazyprogrammer.social.infestit.localization.exception;

import android.app.Activity;
import android.app.AlertDialog.Builder;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;

import br.com.lazyprogrammer.social.infestit.R;

public class GPSNotAvailableException extends GPSException {

	private static final long serialVersionUID = 4558029162530829386L;

	public GPSNotAvailableException() {
		super();
	}

	public GPSNotAvailableException(Activity context, int messageResource) {
		super(context, messageResource);
	}

	public GPSNotAvailableException(String detailMessage) {
		super(detailMessage);
	}

	@Override
	protected Builder buildDialog(final Context context, String message) {
		Builder alertDialogBuilder = new Builder(
				context);
		alertDialogBuilder
				.setMessage(context.getString(R.string.exception_gps_unavailable))
				.setCancelable(false)
				.setPositiveButton(R.string.button_enable_gps,
						new DialogInterface.OnClickListener() {
							@Override
							public void onClick(DialogInterface dialog, int id) {
								Intent callGPSSettingIntent = new Intent(
										android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS);
								context.startActivity(callGPSSettingIntent);
							}
						});
		alertDialogBuilder.setNegativeButton(android.R.string.cancel,
				new DialogInterface.OnClickListener() {
					@Override
					public void onClick(DialogInterface dialog, int id) {
						dialog.dismiss();
						if (context instanceof Activity) {
							((Activity) context).onBackPressed();
						}
						
					}
				});
		return alertDialogBuilder;
	}

}
